package com.awspaas.user.apps.processforsap.pluginImpl;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.model.run.delegate.ProcessInstance;
import com.actionsoft.bpms.commons.at.AbstExpression;
import com.actionsoft.bpms.commons.at.ExpressionContext;
import com.actionsoft.sdk.local.SDK;
import org.apache.commons.lang3.StringUtils;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class GetIsFy extends AbstExpression {
    public GetIsFy(final ExpressionContext atContext, String expressionValue) {
        super(atContext, expressionValue);
    }

    @Override
    public String execute(String expression) {
        ExpressionContext result = getExpressionContext();
        ProcessInstance processInstance = result.getProcessInstance();
        Set<String> resultData = new HashSet<>();
        if (processInstance!=null){
            List<BO> resultList = SDK.getBOAPI().query("BO_EU_SAPORDER_PRO").bindId(processInstance.getId()).list();
            for (BO bo1:resultList){
                String value= bo1.getString("KNTTP");
                resultData.add(value);
            }
        }
        String result11 = StringUtils.join(resultData,",");
        if (result11.contains("A")||result11.contains("K")||result11.contains("F")){
            return "true";
        }else{
            return "false";
        }
    }
}
